﻿using Draco.OWF.Metadata;
using Draco.OWF.Metadata.Impl;
using Draco.OWF.Metadata.DataBinding.Json;
using System.IO;
using Draco.OWF.Metadata.Serialize;
using System;

namespace Draco.OWF.Tester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            ActivityModel ac1 = new ActivityModel("Start");
            ActivityModel ac2 = new ActivityModel("Draco.OWF.Generic.invoke");
            RouteModel route = new RouteModel(ac1.Id, ac2.Id);

            #region
            ac2.InputSchema = new JBindingDataSchema();
            ac2.InputData = new JBindingData();
            ac2.OutputSchema = new JBindingDataSchema();
            ac2.Configuration = new Metadata.ActivityConfiguration();

            ac2.Configuration.AddDataItem("name", "NameTitle");
            ac2.Configuration.AddDataItem("age", "10");

            ac2.InputData.Payload = "{\"name\":\"CName\"}";
            #endregion

            WorkflowModel workflow = new WorkflowModelImpl();
            ac1.Entry = true;
            workflow.AddActivity(ac1);
            workflow.AddActivity(ac2);

            workflow.AddRoute(route);

            //workflow.EndActivity = ac2;

            workflow.Check();

            //IEngineConfiguration config = new EngineConfiguration();
            //IEngine engine = DefaultEngine.OWFEngine;
            //engine.init(config);
            //engine.WorkflowManager.LoadProcess(workflow);
            //engine.CreateJob(workflow, null,null);

            String xml = XmlSerializer.SerializeWorkflowProcess(workflow);
            Console.WriteLine(xml);

            XmlSerializer.SerializeWorkflowProcess(workflow, "D:\\wf2.xml");


            WorkflowModel wf = XmlSerializer.DeserializeWorkflowProcess(xml);
            wf = XmlSerializer.DeserializeWorkflowProcessFromFile("D:\\wf2.xml");
            //using (Stream stream = new FileStream("D:\\wf2.xml", FileMode.OpenOrCreate))
            //{
            //    using (StreamWriter writer = new StreamWriter(stream))
            //    {

            //        System.Xml.Serialization.XmlSerializer xmlSerializer =
            //            new System.Xml.Serialization.XmlSerializer(workflow.GetType());
            //        xmlSerializer.Serialize(writer, workflow);
            //    }
            //}
        }
    }
}
